package com.cqie.practicaltraining.controller;

import com.cqie.practicaltraining.config.result.R;
import com.cqie.practicaltraining.domain.Pasture;
import com.cqie.practicaltraining.dto.PastureSelectDto;
import com.cqie.practicaltraining.service.impl.PastureServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/pasture")
@Api("牧场管理")
public class pastureController {
    @Autowired
    private PastureServiceImpl pastureService;

    @PostMapping("/getPastureByCondition")
    @ApiOperation(value = "条件查询牧场信息")
    public R getAllPasture(@RequestBody @Validated PastureSelectDto pastureSelectDto) {
        return pastureService.getPastureCondition(pastureSelectDto);
    }

    @PostMapping("/getPastureByPastureId")
    @ApiOperation(value = "根据id获取牧场信息")
    public R getPastureByPastureId(@RequestParam Long pastureId) {
        return pastureService.getPastureByPastureId(pastureId);
    }

    @PostMapping("/addPasture")
    @ApiOperation(value = "添加牧场信息")
    public R addPasture(@RequestBody @Validated Pasture pasture) {
        return pastureService.addPasture(pasture);
    }

    @PutMapping("/editPasture")
    @ApiOperation(value = "修改牧场信息")
    public R editPasture(@RequestBody @Validated Pasture pasture) {
        return pastureService.editPasture(pasture);
    }

    @PutMapping("/changeStatus")
    @ApiOperation(value = "修改牧场状态")
    public R changeStatus(@RequestParam Long pastureId) {
        return pastureService.changeStatus(pastureId);
    }

    @GetMapping("/getAllPastureName")
    @ApiOperation(value = "获取所有牧场名称")
    public R getAllPastureName() {
        return pastureService.getAllPastureName();
    }
}
